package com.cg.service;

import com.cg.mapper.UserMapper;
import com.cg.pojo.entity.UserEntity;
import com.cg.pojo.vo.UserRegisterVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class UserService {
    @Autowired
    UserMapper userMapper;

    public List<UserRegisterVo> getList() {

        return userMapper.selectAll();
    }


    public boolean login(String username, String password) {

        UserEntity user = userMapper.selectByUsername(username);
        if (user== null) {
            System.out.println("用户不存在");
            return false;
        }
        return password.equals(user.getPassword());
    }


    public boolean register(UserRegisterVo user) {
        if(userMapper.selectByUsername(user.getUsername())!= null){
            return false;
        }
        userMapper.add(user);
        return true;
    }


    public UserEntity getUserByUsername(String username) {
        UserEntity user = userMapper.selectByUsername(username);
        return user;
    }


    public void updateUser(UserRegisterVo user) {
        userMapper.update(user);
    }
}
